/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Entry.EntryType;
/*     */ import com.zimbra.cs.account.ldap.LdapDIT;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.account.ldap.entry.LdapDomain;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZSearchScope;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_32557
/*     */   extends UpgradeOp
/*     */ {
/*     */   private static class Bug32557Visitor
/*     */     extends SearchLdapOptions.SearchLdapVisitor
/*     */   {
/*     */     private UpgradeOp upgradeOp;
/*     */     private ZLdapContext modZlc;
/*     */     private int mDomainsVisited;
/*     */     
/*     */     Bug32557Visitor(UpgradeOp upgradeOp, ZLdapContext modZlc)
/*     */     {
/*  47 */       super();
/*  48 */       this.upgradeOp = upgradeOp;
/*  49 */       this.modZlc = modZlc;
/*     */     }
/*     */     
/*     */     public void visit(String dn, IAttributes ldapAttrs)
/*     */     {
/*     */       try
/*     */       {
/*  56 */         Domain domain = new LdapDomain(dn, (ZAttributes)ldapAttrs, this.upgradeOp.prov.getConfig().getDomainDefaults(), this.upgradeOp.prov);
/*     */         
/*  58 */         visit(domain);
/*     */       } catch (ServiceException e) {
/*  60 */         this.upgradeOp.printer.println("entry skipped, encountered error while processing entry at:" + dn);
/*  61 */         this.upgradeOp.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */     
/*     */     private void visit(Domain domain)
/*     */     {
/*  67 */       this.mDomainsVisited += 1;
/*     */       
/*  69 */       Map<String, Object> attrs = new HashMap();
/*  70 */       attrs.put("+objectClass", "amavisAccount");
/*     */       try
/*     */       {
/*  73 */         this.upgradeOp.printer.format("Updating domain %-30s: objectClass=amavisAccount\n", new Object[] { domain.getName() });
/*     */         
/*  75 */         this.upgradeOp.modifyAttrs(this.modZlc, domain, attrs);
/*     */       }
/*     */       catch (ServiceException e) {
/*  78 */         this.upgradeOp.printer.println("Caught ServiceException while modifying domain " + domain.getName());
/*  79 */         this.upgradeOp.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */     
/*     */     void reportStat() {
/*  84 */       this.upgradeOp.printer.println();
/*  85 */       this.upgradeOp.printer.println("Number of domains modified = " + this.mDomainsVisited);
/*  86 */       this.upgradeOp.printer.println();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  97 */     String query = "(&(objectClass=zimbraDomain)(!(objectClass=amavisAccount)))";
/*  98 */     String[] bases = this.prov.getDIT().getSearchBases(16);
/*  99 */     String[] attrs = { "objectClass", "zimbraId", "zimbraDomainName" };
/*     */     
/*     */ 
/*     */ 
/* 103 */     ZLdapContext zlc = null;
/* 104 */     Bug32557Visitor visitor = new Bug32557Visitor(this, zlc);
/*     */     try
/*     */     {
/* 107 */       zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */       
/* 109 */       for (String base : bases)
/*     */       {
/* 111 */         if (this.verbose) {
/* 112 */           this.printer.println("LDAP search base: " + base);
/* 113 */           this.printer.println("LDAP search query: " + query);
/* 114 */           this.printer.println();
/*     */         }
/*     */         
/* 117 */         SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), attrs, 0, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
/*     */         
/*     */ 
/*     */ 
/* 121 */         zlc.searchPaged(searchOpts);
/*     */       }
/*     */     }
/*     */     finally {
/* 125 */       LdapClient.closeContext(zlc);
/* 126 */       if (visitor != null) {
/* 127 */         visitor.reportStat();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   Description getDescription() {
/* 133 */     return new Description(this, new String[] { "objectClass" }, new Entry.EntryType[] { Entry.EntryType.DOMAIN }, null, "amavisAccount", "Add objectClass=amavisAccount to all existing domains.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_32557.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */